package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 会话健康状态枚举
 *
 * <p>定义批阅会话的健康状态，包括健康、非活跃、警告、不健康等。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum SessionHealthStatus implements BaseEnum {

    /** 健康 */
    HEALTHY("HEALTHY", "健康"),

    /** 非活跃 */
    INACTIVE("INACTIVE", "非活跃"),

    /** 警告 */
    WARNING("WARNING", "警告"),

    /** 不健康 */
    UNHEALTHY("UNHEALTHY", "不健康");

    private final String code;
    private final String description;

    SessionHealthStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static SessionHealthStatus fromCode(String code) {
        for (SessionHealthStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown session health status code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static SessionHealthStatus fromDescription(String description) {
        for (SessionHealthStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown session health status description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}